package com.cqupt.controller;

import com.cqupt.pojo.Package;
import com.cqupt.service.PackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PackageController {
    @Autowired
    private PackageService packageService;
    //查询
    @RequestMapping("/package/selectPackage")
    @ResponseBody
    public List selectPackage(Integer number) {

       number = 1;
       return  packageService.selectPackage(number);

    }
    @RequestMapping("/package/add")
    @ResponseBody
    public int insertPackage(Package pac) {
        String[] list = pac.getPicpath().split("\\\\");
        String path = "http://localhost:8080/boss_system/picture/" + list[1];
        pac.setPicpath(path);
        return packageService.insertPackage(pac);

    }

    @RequestMapping("/package/delete")
    @ResponseBody
    public int insertPackage(Integer id) {
        //id = 8;
        return packageService.deletePackage(id);

    }

    //上架套餐
    @RequestMapping("/package/onlinePackage")
    @ResponseBody
    public int onlinePackage(Integer id) {
        //id = 1;
        return packageService.onlinePackage(id);

    }

    //下架套餐
    @RequestMapping("/package/offlinePackage")
    @ResponseBody
    public int offlinePackage(Integer id) {
        //id = 1;
        return packageService.offlinePackage(id);

    }

    //套餐更新
    @RequestMapping("/package/updatePackage")
    @ResponseBody
    public int offlinePackage(Package pac) {
        //pac.setPrice(2345678.0);
        //pac.setDescription("11111");
        return packageService.updatePackage(pac);

    }
}
